import java.io.*;
public class Main {
	int number;
	Main key;
	public Main() {
		number=0;
		key=null;	
	}
	public void Link(int x,Main y[]) {
		number=x+1;
		key=y[x+1];
	}
	public static void main(String[] args) {
		int n,k,m,i;
		n=5;
		k=1;
		m=2;
		Main p[]=new Main[n];
		Main q;
		for(i=0;i<n;i++)
			p[i]=new Main();
		for(i=0;i<n-1;i++)
			p[i].Link(i, p);
		p[n-1].key=p[0];
		p[n-1].number=n;
		System.out.print("出队序号依次为：");
		while(n!=1)
		{
			q=p[k-1];	
			for(i=1;i<m-1;i++)		
				q=q.key;
			System.out.print(q.key.number+"  ");
			q.key=p[q.key.number-1].key;
			k=q.key.number;	
			n=n-1;		
		}
		System.out.print("\n");
		System.out.println("大王为："+k+"  ");
	}
}